<!-- 评价 -->
<template>
	<view>
		<u-navbar :isFixed="true" title="评价" :borderBottom="false"></u-navbar>
		<go-top :scrollTop="scrollTop"></go-top>
		<view class="tabs">
			<u-tabs :list="typelist" sticky :current="current" active-color="#38BE8C" inactive-color="#000000"
				@change="change"></u-tabs>
		</view>
		<view class="block"></view>
		<block v-if="current==0">
			<view class="card" v-for="(item,index) in list" :key="index">
				<view class="flex_bet_align">
					<view class="flex_align">
						<image class="avatar" :src="item.avatar"></image>
						<view>
							<view class="name">{{item.nickname}}</view>
							<view class="time">{{item.createtime}}</view>
						</view>
					</view>
					<u-rate :count="5" v-model="item.level" disabled active-color="#FFA038"></u-rate>
				</view>
				<view class="content">{{item.content}}</view>
				<view class="gallery flex_align">
					<image class="img" v-for="(item2,index2) in item.images" :key="index2" :src="item2"
						@click="$plug.showImg(item.images,item2)"></image>
				</view>
				<navigator :url="'/home/index/supplydetail?id='+item.content_json.id" hover-class="none"
					class="goods flex_align" v-if="item.content_json!=null">
					<image class="goodsImage" :src="item.content_json.image" mode="widthFix"></image>
					<view>
						<view class="goodsName">{{item.content_json.title}}</view>
						<view class="price">￥{{item.content_json.money}}/{{item.content_json.unit}}</view>
					</view>
				</navigator>
				<view class="reply flex_align" v-if="item.rcontent.length>0">
					<view class="title">卖家回复：</view>
					<view class="msg">{{item.rcontent}}</view>
				</view>
			</view>
		</block>
		<block v-if="current==1">
			<view class="card" v-for="(item,index) in list" :key="index">
				<view class="flex_bet_align">
					<view class="flex_align">
						<image class="avatar" :src="item.avatar"></image>
						<view>
							<view class="name">{{item.nickname}}</view>
							<view class="time">{{item.createtime}}</view>
						</view>
					</view>
					<u-rate :count="5" v-model="item.level" disabled active-color="#FFA038"></u-rate>
				</view>
				<view class="flex_align">
					<view class="content">{{item.content}}</view>
					<view class="btn" v-if="item.rcontent.length<1" @click="reply(item.id)">回复</view>
				</view>
				<view class="gallery flex_align">
					<image class="img" v-for="(item2,index2) in item.images" :key="index2" :src="item2"
						@click="$plug.showImg(item.images,item2)"></image>
				</view>
				<navigator :url="'/home/index/supplydetail?id='+item.content_json.id" hover-class="none"
					class="goods flex_align">
					<image class="goodsImage" :src="item.content_json.image" mode="widthFix"></image>
					<view>
						<view class="goodsName">{{item.content_json.title}}</view>
						<view class="price">￥{{item.content_json.money}}/{{item.content_json.unit}}</view>
					</view>
				</navigator>
				<view class="reply flex_align" v-if="item.rcontent.length>0">
					<view class="title">卖家回复：</view>
					<view class="msg">{{item.rcontent[0].content}}</view>
				</view>
			</view>
		</block>
		<view class="not_more" v-if="list.length<1">
			<image src="../static/img/wxiaoxi.png" mode="widthFix"></image>
			<view class="text">暂无评价</view>
		</view>
		<view class="nomore" v-if="nomore&&list.length>0">—— · 没有更多了 · ——</view>
		<u-popup v-model="showinput" :mask="true" mode="bottom" border-radius="10" :closeable="true"
			:safe-area-inset-bottom="true">
			<view class="inputdiv">
				<view class="h3">回复内容</view>
				<u-input confirm-type="send" v-model="contents" type="text" focus="true" :border="false"
					placeholder="请输入回复语" placeholderStyle="color:#B9B9B9" :auto-height="false" class="lineputs"
					:clearable="false" @confirm="evaluate" />
			</view>
		</u-popup>
	</view>
</template>

<script>
	var _this, $paginator, shake;
	export default {
		data() {
			return {
				typelist: [{
						name: '我的评价'
					},
					{
						name: '我收到的评价'
					}
				],
				current: 1,
				rate: 5,
				list: [],
				nomore: false,
				// 回到头部按钮距离
				scrollTop: 0,
				// 开启回复
				showinput: false,
				// 回复语言
				contents: "",
				// 回复的id
				replyid: 0
			}
		},
		onLoad() {
			_this = this
			$paginator = new _this.$paginator(_this.$api)
			_this.getdata(true)
		},
		//监听页面滚动
		onPageScroll(res) {
			this.scrollTop = res.scrollTop
		},
		//下拉刷新
		onPullDownRefresh() {
			$paginator = new _this.$paginator(_this.$api)
			_this.getdata(true)
		},
		onReachBottom: function() {
			$paginator.nextPager(() => {
				_this.getdata()
			})
		},
		methods: {
			getdata: function(firstLoad = false) {
				$paginator.getData('mycommentlist', {
					comment_type: parseInt(_this.current) + 1
				}, (data) => {
					if (firstLoad) {
						_this.list = data.list ? data.list : []
					} else {
						_this.list = _this.list.concat(data.list)
					}
					_this.nomore = data.nomore
				})
			},
			// 防抖点击
			click_shake(fn) {
				if (!_this.shake) {
					fn && typeof fn === 'function' && fn()
					_this.shake = true
					setTimeout(function() {
						_this.shake = false
					}, 500)
				}
			},
			change(e) {
				this.current = e
				_this.list = []
				$paginator = new _this.$paginator(_this.$api)
				_this.getdata(true)
			},
			reply(id) {
				_this.replyid = id
				_this.showinput = true
			},
			evaluate() {
				_this.click_shake(() => {
					if (_this.contents.length < 1) {
						uni.showToast({
							title: "请输入回复语言",
							icon: "none"
						})
					} else {
						_this.$api.post("savecomment", {
							select_type: 2,
							other_type: 2,
							contents: _this.contents,
							type_id: _this.replyid
						}).then(data => {
							uni.showToast({
								title: "回复成功"
							})
							_this.contents = ""
							_this.showinput = false
							$paginator = new _this.$paginator(_this.$api)
							_this.getdata(true)
						});
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.tabs {
		display: flex;
		justify-content: center;
	}

	.block {
		width: 750rpx;
		height: 8rpx;
		opacity: 0.5;
		background: #eeeeee;
	}

	.card {
		padding: 23rpx 25rpx;
		border-bottom: 1rpx solid #E6E6E6;

		.avatar {
			width: 82rpx;
			height: 82rpx;
			border-radius: 50%;
			background: #FDC2D6;
			margin-right: 10rpx;
		}

		.name {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			text-align: left;
			color: #333333;
		}

		.time {
			font-size: 20rpx;
			margin-top: 16rpx;
			font-family: PingFang SC;
			font-weight: 400;
			text-align: left;
			color: #999999;
		}

		.content {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			text-align: left;
			color: #333333;
			margin: 36rpx 0 23rpx;
			flex: 1;
		}

		.btn {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Medium;
			font-weight: 500;
			text-align: left;
			color: #33b1f2;
			margin: 36rpx 0 23rpx;
		}

		.sku {
			font-size: 20rpx;
			font-family: PingFang SC;
			font-weight: 500;
			text-align: left;
			color: #999999;
			margin-bottom: 23rpx;
		}

		.gallery {
			margin-bottom: 29rpx;
			flex-wrap: wrap;

			.img {
				width: 220rpx;
				height: 220rpx;
				border-radius: 16rpx;
				background: #EEEEEE;
				margin-right: 20rpx;
				margin-bottom: 10rpx;
			}

			.img:nth-child(3n+3) {
				margin-right: 0;
			}
		}

		.goods {
			width: 698rpx;
			height: 147rpx;
			background: #F5F5F5;
			border-radius: 8rpx;
			padding: 17rpx 21rpx 27rpx;

			.goodsImage {
				width: 103rpx;
				height: 103rpx;
				background: #EEEEEE;
				margin-right: 20rpx;
			}

			.goodsName {
				font-size: 26rpx;
				font-family: PingFang SC, PingFang SC-Medium;
				font-weight: 500;
				text-align: left;
				color: #222222;
				line-height: 34rpx;
			}

			.price {
				font-size: 20rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				text-align: left;
				color: #666666;
				line-height: 29rpx;
				margin-top: 13rpx;
			}
		}

		.reply {
			padding-top: 27rpx;
			padding-bottom: 70rpx;
			margin-top: 32rpx;
			border-top: 1rpx solid #EEEEEE;

			.title {
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				text-align: left;
				color: #969696;
			}

			.msg {
				font-size: 26rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				text-align: left;
				color: #3e4350;
			}
		}
	}

	.inputdiv {
		width: 100%;
		padding: 0 3% 40rpx;
		background-color: #FFFFFF;

		.h3 {
			font-size: 30rpx;
			text-align: center;
			line-height: 120rpx;
			font-weight: bold;
		}
	}
</style>
